/*
 * @Description: 
 * @Version: 1.0
 * @Autor: 飞云
 * @LastEditTime: 2020-12-08 19:56:50
 */

awemeFace();

setExceptionCallback(function (msg) {
    logd(" 异常停止消息: " + msg)
});

setStopCallback(function () {
    logd("我是停止回调")
});

function awemeFace() {
    home();
    let packageName = 'com.ss.android.ugc.aweme.lite';
    utils.openApp(packageName);

    let pages = random(3, 5);   //指定需浏览的视频随机数量
    logi('需浏览 ' + pages + '个视频');

    for (let i = 0; i < pages; i++) {
        let activity = getRunningActivity();
        switch (activity) {
            case 'com.ss.android.ugc.aweme.main.MainActivity':
                let times = random(5000, 10000);  //单个视频浏览时长
                logd('等待 ' + times + '毫秒');
                sleep(times);

                // 设定坐标，注意避开悬浮窗
                let x = device.getScreenWidth() * 7 / 10;
                let y = device.getScreenHeight() * 8 / 10;
                let x1 = device.getScreenWidth() * 7 / 10;
                let y1 = device.getScreenHeight() * 1.5 / 10;

                // 随机滑屏
                let jumpNum = random(1, 5);
                for (let j = 0; j < jumpNum; j++) {
                    if (j != jumpNum - 1) {
                        logd('跳过第 ' + (j + 1) + '屏');
                    }
                    // 滑动屏幕，注意避开悬浮窗
                    if (rndSwipe(x, y, x1, y1, 100, 200, 200)) {
                        sleep(3000);
                    }
                }

                logi('浏览第 ' + (i + 1) + '个视频');
                break;
            default:
                break;
        }
    }
}
